home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_util / bsrc_260.zip / SRC.ZIP / PUT_LANG.C < prev    next >
C/C++ Source or Header  |  1996-02-20  |  9KB  |  269 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*               This module was written by Vince Perriello                 */
  13. /*                                                                          */
  14. /*            BinkleyTerm Language Compiler File Output Module              */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46.  
  47. #include "language.h"
  48.  
  49. /*
  50.  * put_language -- store compiled language file
  51.  *
  52.  * This is a simple four step operation
  53.  *
  54.  * 1. Open file for write
  55.  * 2. Write out the used part of the fixup array
  56.  * 3. Write out the used part of the memory block
  57.  * 4. Close the file
  58.  *
  59.  */
  60.  
  61. int 
  62. put_language (char *name_of_file)
  63. {
  64.     FILE *fpt;                    /* stream pointer            */
  65.     int error;                    /* Internal error value      */
  66.     int wanna_write;            /* How many we wanna write   */
  67.     int written;                /* How many we really write  */
  68.     long total_length;
  69.  
  70.    /*
  71.     * Open the file for output now.
  72.     *
  73.     */
  74.  
  75.     fpt = fopen (name_of_file, "wb");    /* Open the file             */
  76.     if (fpt == NULL)            /* Were we successful?       */
  77.     {
  78.         fprintf (stderr, "Can not open output file %s\n", name_of_file);
  79.         return (-1);            /* Return failure to caller  */
  80.     }
  81.  
  82.    /*
  83.     * OK. Looking good so far. Write out the pointer array.
  84.     * Don't forget that last NULL pointer to terminate it!
  85.     *
  86.     */
  87.  
  88.     wanna_write = pointer_size;    /* Number of things to write */
  89.  
  90.     /* Write the string table count */
  91.     /* and string memory size */
  92.  
  93.     LangHdr.ElemCnt = wanna_write;
  94.     LangHdr.PoolSize = memory_size;
  95.     written = fwrite ((char *) &LangHdr, sizeof (struct _lang_hdr), 1, fpt);
  96.  
  97.     if (written != 1)
  98.     {
  99.         fprintf (stderr, "Unable to language file header\n");
  100.         fclose (fpt);
  101.         return (-2);
  102.     }
  103.     written = fwrite ((char *) pointers, sizeof (char *), wanna_write, fpt);
  104.  
  105.     if (written != wanna_write)
  106.     {
  107.         fprintf (stderr, "Unable to write fixup array to output file\n");
  108.         fclose (fpt);
  109.         return (-2);
  110.     }
  111.     fprintf (stderr, "Pointer Table Elements: %d\n", wanna_write);
  112.  
  113.    /*
  114.     * Pointer array is there. Now write out the characters.
  115.     *
  116.     */
  117.  
  118.     wanna_write = memory_size;    /* Number of chars to write  */
  119.     written = fwrite (memory, sizeof (char), wanna_write, fpt);
  120.  
  121.     if (written != wanna_write)
  122.     {
  123.         fprintf (stderr, "Unable to write characters to output file\n");
  124.         fclose (fpt);
  125.         return (-3);
  126.     }
  127.  
  128.    /*
  129.     * Write the terminal mode remap table, first the count,
  130.     * then the table itself.
  131.     */
  132.  
  133.     written = fwrite ((char *) &TrmnlAccelCnt, sizeof (short), 1, fpt);
  134.  
  135.     if (written != 1)
  136.     {
  137.         fprintf (stderr, "Unable to write Terminal Accel Count\n");
  138.         fclose (fpt);
  139.         return (-2);
  140.     }
  141.     wanna_write = TrmnlAccelCnt;
  142.  
  143.     written = fwrite ((char *) TrmnlAccelTbl,
  144.         sizeof (struct _key_fnc),
  145.         wanna_write,
  146.         fpt);
  147.  
  148.     if (written != wanna_write)
  149.     {
  150.         fprintf (stderr, "Unable to write terminal accel array to output file\n");
  151.         fclose (fpt);
  152.         return (-2);
  153.     }
  154.  
  155.     fprintf (stderr, "Terminal Mode Remap Table Size: %d\n", wanna_write);
  156.  
  157.    /*
  158.     * Write the unattended mode remap table, first, the count,
  159.     * then the table itself.
  160.     */
  161.  
  162.     written = fwrite ((char *) &UnattendedAccelCnt, sizeof (short), 1, fpt);
  163.  
  164.     if (written != 1)
  165.     {
  166.         fprintf (stderr, "Unable to Write Unattended Accel Count\n");
  167.         fclose (fpt);
  168.         return (-2);
  169.     }
  170.     wanna_write = UnattendedAccelCnt;
  171.  
  172.     written = fwrite ((char *) UnattendedAccelTbl,
  173.         sizeof (struct _key_fnc),
  174.         wanna_write,
  175.         fpt);
  176.  
  177.     if (written != wanna_write)
  178.     {
  179.         fprintf (stderr, "Unable to write terminal accel array to output file\n");
  180.         fclose (fpt);
  181.         return (-2);
  182.     }
  183.  
  184.     fprintf (stderr, "Unattended Mode Remap Table Size: %d\n", wanna_write);
  185.  
  186.    /*
  187.     * Write the product code table, first the string table count and
  188.     * string memory size, then the pointer array.
  189.     */
  190.  
  191.     written = fwrite ((char *) &PrdctHdr, sizeof (struct _lang_hdr), 1, fpt);
  192.  
  193.     if (written != 1)
  194.     {
  195.         fprintf (stderr, "Unable to write product code header\n");
  196.         fclose (fpt);
  197.         return (-2);
  198.     }
  199.  
  200.     wanna_write = PrdctHdr.ElemCnt;    /* Number of things to write */
  201.     written = fwrite ((char *) PrdctTbl, sizeof (char *), wanna_write, fpt);
  202.  
  203.     if (written != wanna_write)
  204.     {
  205.         fprintf (stderr, "Unable to write prdct fixup array to output file\n");
  206.         fclose (fpt);
  207.         return (-2);
  208.     }
  209.  
  210.    /*
  211.     * Pointer array is there. Now write out the characters.
  212.     *
  213.     */
  214.  
  215.     wanna_write = PrdctHdr.PoolSize;    /* Number of chars to write  */
  216.     written = fwrite (PrdctMem, sizeof (char), wanna_write, fpt);
  217.  
  218.     if (written != wanna_write)
  219.     {
  220.         fprintf (stderr, "Unable to write characters to output file\n");
  221.         fclose (fpt);
  222.         return (-3);
  223.     }
  224.  
  225.     fprintf (stderr, "Product Code Table Size: %d\n", PrdctHdr.ElemCnt);
  226.  
  227.    /*
  228.     * Write out the ANSI table.
  229.     */
  230.  
  231.     written = fwrite ((char *) &AnsiHdr, sizeof (struct _lang_hdr), 1, fpt);
  232.  
  233.     if (written != 1)
  234.     {
  235.         fprintf (stderr, "Unable to write ANSI map header\n");
  236.         fclose (fpt);
  237.         return (-2);
  238.     }
  239.  
  240.     wanna_write = AnsiHdr.PoolSize;
  241.     written = fwrite (AnsiMem, sizeof (char), wanna_write, fpt);
  242.  
  243.     if (written != wanna_write)
  244.     {
  245.         fprintf (stderr, "Unable to write characters to output file\n");
  246.         fclose (fpt);
  247.         return (-3);
  248.     }
  249.  
  250.     fprintf (stderr, "ANSI Translate Table Size: %d\n", AnsiHdr.ElemCnt);
  251.  
  252.    /*
  253.     * Everything's there now. Close the file.
  254.     */
  255.  
  256.     total_length = ftell (fpt);
  257.  
  258.     fprintf (stderr, "Size of complete table: %ld\n", total_length);
  259.  
  260.     error = fclose (fpt);
  261.     if (error != 0)
  262.     {
  263.         fprintf (stderr, "Unable to properly close output file %s\n", name_of_file);
  264.         return (-4);
  265.     }
  266.  
  267.     return (0);
  268. }
  269.